package org.example.rtc.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@Component
public class SaInnerceptor extends SaInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (StpUtil.isLogin()) {
            Object token = StpUtil.getLoginIdByToken(request.getHeader("token"));
            if (token != null) {
                return true;
            }
            throw new RuntimeException("token 无效");
        }else {
            throw new RuntimeException("用户未登陆");
        }
    }
}
